/*
 * ChatDude.scala
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sample.comet

import net.liftweb._
import http._
import S._
import SHtml._

class ChatDude(info: CometActorInitInfo) extends CometActor(info) {
  private var msgs: List[String] = Nil

  override def localSetup {
    ChatServer ! Listen(this)
    super.localSetup
  }

  def defaultPrefix = "foo"
  
  override def localShutdown {
    ChatServer ! Unlisten(this)
    super.localShutdown
  }

  def render =
  <xml:group>
    <ul>
      {
        msgs.take(40).reverse.map(m => <li>{m}</li>)
      }
      </ul>
      {
        ajaxForm(
          <div>
          {text("", ChatServer ! _)}
          <input type="submit" value="post" />
          </div>
        )
      }
  </xml:group>

  override def lowPriority = {
    case Update(newmsgs) => msgs = newmsgs
      reRender(false)
  }

}
